package ${package.Controller};

import ${package.Service}.${table.serviceName};
import ${package.Entity}.${entity};
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.List;

/**
* ${table.comment!} 控制器
*
* @author ${author}
* @since ${date}
*/
@RestController
@RequestMapping("/api/${package.ModuleName}/${table.entityPath}")
public class ${table.controllerName} {

@Autowired
private ${table.serviceName} ${table.entityPath}Service;

/**
* 新增${entity}
*/
@PostMapping("/save")
public Boolean save(@RequestBody ${entity} ${table.entityPath}) {
return ${table.entityPath}Service.save(${table.entityPath});
}

/**
* 删除${entity}
*/
@DeleteMapping("/delete/{id}")
public Boolean delete(@PathVariable Long id) {
return ${table.entityPath}Service.removeById(id);
}

/**
* 修改${entity}
*/
@PostMapping("/update")
public Boolean update(@RequestBody ${entity} ${table.entityPath}) {
return ${table.entityPath}Service.updateById(${table.entityPath});
}

/**
* 根据ID查询${entity}
*/
@GetMapping("/{id}")
public ${entity} findById(@PathVariable Long id) {
return ${table.entityPath}Service.getById(id);
}

/**
* 分页查询${entity}
*/
@GetMapping("/page")
public Page<${entity}> pageQuery(
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize) {
return ${table.entityPath}Service.page(new Page<>(pageNum, pageSize));
}

/**
* 查询全部${entity}
*/
@GetMapping("/list")
public List<${entity}> listAll() {
return ${table.entityPath}Service.list();
}
}
